<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>

		.cls{
			background-color:rgba(0,0,0,.3);
		}

	</style>
</head>
<body>
	<input type="button" value="开灯" id="btn">
	<script>
		var btnObj = document.getElementById('btn');
		var bodyObj =document.getElementsByTagName("body")[0];
		btn.onclick = function(){
			// if(this.value == "开灯"){
			// 	this.value = "关灯"
			// 	bodyObj.style.backgroundColor = "rgba(0,0,0,.3)"

			// }else{
			// 	this.value = "开灯"
			// 	bodyObj.style.backgroundColor = ""
			// }
			// 
			// if(this.value =="开灯"){
			// 	this.value = "关灯"
			// 	bodyObj.className = "cls"
			// }else{
			// 	this.value = "开灯"
			// 	bodyObj.className = ""
			// }

			// 三元表达式
			this.value =="开灯"?{this.value = "关灯";
			bodyObj.className = "cls"}:	{this.value = "开灯";
			bodyObj.className = ""}
		}



	</script>
</body>
</html>